<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% add_crumb t('crumbs.users', "Users") %>
<% @active_tab = "users" %>
<% content_for :page_title do %>
  <% if @query %>
    <%= t('search_for_user', 'User Search results for %{user_name}', :user_name => (params[:user][:name] rescue '')) %>
  <% else %>
    {{#t}}All Users{{/t}}
  <% end %>
<% end %>

<% content_for :right_side do %>
  <div class="rs-margin-bottom">
    <% if can_do(@context, @current_user, :manage_groups) %>
      <a href="<%= context_url(@context, :context_groups_url) %>" class="btn button-sidebar-wide user_groups"><i class="icon-group"></i> {{#t}}View User Groups{{/t}}</a>
    <% end %>
    <% if service_enabled?(:avatars) %>
      <a href="<%= context_url(@context, :context_avatars_url) %>" class="btn button-sidebar-wide manage_profile_pictures"><i class="icon-user"></i> {{#t}}Manage Profile Pictures{{/t}}</a>
    <% end %>
  </div>

  <% if @enrollment_terms.size > 1 %>
    <h2>{{#t}}Choose Term{{/t}}</h2>
    <div class="rs-margin-bottom">
      <label for="enrollment_term"><%= before_label('show_users_for_term', 'Show users with enrollments in the term') %></label><br />
      <%= form_tag(account_users_path, :method => :get) do %>
        <input name="focus" type="hidden" value="enrollment_term_id"/>
        {{> views/shared/enrollment_term_select}}
      <% end %>
    </div>
  <% end %>

  {{> views/shared/accounts_right_side_shared}}
  {{> views/accounts/add_course_or_user}}
<% end %>

<% if @query %>
  <h1><%= t('titles.search_results', 'Search results for "%{search_term}"', :search_term => (params[:user][:name] rescue '')) %></h1>
  <%= t('no_results_found', "No Results Found") if @users.empty? %>
<% else %>
  <h1>{{#t}}All Users{{/t}}</h1>
<% end %>

<%= will_paginate(@users, :style=>"margin-bottom: 1em;") %>

<ul class="users">
  <% @users.each do |user| %>
    <li id="user_<%= user.id %>" class="user">
      <%= link_to(user.last_name_first_or_unnamed, context_url(@context, :context_user_url, user)) %>
    </li>
  <% end %>
</ul>

<%= will_paginate(@users, :style=>"margin-top: 1em;") %>

<% js_bundle 'legacy/users_index' %>
<% js_bundle 'focus_helper' %>
